<!-- 瀑布流列表 -->
<template>
	<view
		:style="'order:'+Item.order+';'+Item.css"
		class="list-waterfall">
		<view class="box">
			<template v-if="listState == 'success'">
				<view
					@click="$_To('post/post?pid='+item.pid)"
					class="for"
					v-for="item in list">
					<template v-if="item.files">
						<view
							class="image"
							v-if="item.files.images">
							<image :src="item.files.images[0].imageRatioUrl" mode="widthFix"></image>
						</view>
					</template>
					<view class="title">
						{{item.title?item.title:$_filterHtml(item.content)}}
					</view>
					<view class="info">
						<view class="user">
							<view class="avatar">
								<image :src="item.author.avatar" mode="widthFix"></image>
							</view>
							<text>{{item.author.nickname}}</text>
						</view>
						<view class="comment">
							<text class="iconfont icon-pinglun1"></text>
							<text>{{item.commentCount}}</text>
						</view>
					</view>
				</view>
				<view
					class="for page"
					v-if="Item.page"
					@click="getList('more')">
					{{listPageText}}
				</view>
			</template>
		</view>
		<template v-if="listState == 'loading'">
			<view class="loading">
				<view class="loading-css"></view>
				<view class="loading-css"></view>
				<view class="loading-css"></view>
				<view class="loading-css"></view>
				<view class="loading-css"></view>
				<view class="loading-css"></view>
				<view class="loading-css"></view>
				<view class="loading-css"></view>
				<view class="loading-css"></view>
				<view class="loading-css"></view>
				<view class="loading-css"></view>
				<view class="loading-css"></view>
			</view>
		</template>
		<template v-if="listState == 'empty'">
			<public-empty></public-empty>
		</template>
	</view>
</template>

<script>
	export default {
		name:"list-waterfall",
		props:{
			Item:{
				type:Object,
				default:null
			},
			YrConfig:{
				type:String,
				default:""
			},
			listGid:{
				type:String,
				default:""
			},
			listHid:{
				type:String,
				default:""
			}
		},
		data() {
			return {
				list:[],
				listState:"loading",
				listPage:2,
				listPageText:"点击加载更多",
			};
		},
		mounted(){
			this.getList();
		},
		methods: {
			getList(more){
				if(this.Item.query.gid == 'empty'){
					this.Item.query.gid = "";
					this.listGid = ""
				}
				if(this.Item.query.hid == 'empty'){
					this.Item.query.hid = "";
					this.listHid = ""
				}
				if(more == 'more'){
					this.listPageText = "加载中..."
				}
				this.$_Request(
					"GET","/api/v2/post/list",
					{
						"mapId": this.Item.query.mapId,
						"mapLng": this.Item.query.mapLng,
						"mapLat": this.Item.query.mapLat,
						"uidOrUsername": this.Item.query.uidOrUsername,
						"hid": this.Item.query.hid?this.Item.query.hid:this.listHid,
						"gid": this.Item.query.gid?this.Item.query.gid:this.listGid,
						"includeSubgroups": this.Item.query.includeSubgroups,
						"allDigest": this.Item.query.allDigest,
						"digestState": this.Item.query.digestState,
						"stickyState": this.Item.query.stickyState,
						"contentType": this.Item.query.contentType,
						"createdDays": this.Item.query.createdDays,
						"createdDate": this.Item.query.createdDate,
						"createdDateGt": this.Item.query.createdDateGt,
						"createdDateLt": this.Item.query.createdDateLt,
						"likeCountGt": this.Item.query.likeCountGt,
						"likeCountLt": this.Item.query.likeCountLt,
						"followCountGt": this.Item.query.followCountGt,
						"followCountLt": this.Item.query.followCountLt,
						"blockCountGt": this.Item.query.blockCountGt,
						"blockCountLt": this.Item.query.blockCountLt,
						"commentCountGt": this.Item.query.commentCountGt,
						"commentCountLt": this.Item.query.commentCountLt,
						"orderType": this.Item.query.orderType,
						"orderDirection": this.Item.query.orderDirection,
						"blockGroups": this.Item.query.blockGroups + this.YrConfig,
						"blockHashtags": this.Item.query.blockHashtags,
						"pluginRatingId": this.Item.query.pluginRatingId,
						"pageSize": this.Item.query.pageSize,
						"page":more == 'more' ? this.listPage : "",
						"whitelistKeys":"pid,title,content,author.avatar,author.nickname,author.nicknameColor,commentCount,files.images.0,commentCount"
					},
					(res) => {
						if(more == 'more'){
							if(res.data.data.list.length){
								this.list = this.list.concat(res.data.data.list);
								this.listPageText = "点击加载更多";
								this.listPage++
							}else{
								this.listPageText = "没有数据啦"
							}
							this.$store.commit('mutationsStateonReachBottomStatus',true)
						}else{
							if(res.data.data.list.length){
								this.list = res.data.data.list;
								this.listState = "success";
							}else{
								this.listState = "empty"
							}
						}
					}
				)
			}
		}
	}
</script>

<style lang="scss" scoped>
.list-waterfall{
	.box{
		column-count: 2; /* 设置列数 */
		column-gap: 25rpx; /* 设置列间距 */
		.for {
			break-inside: avoid; /* 防止元素被拆分到不同列 */
			margin-bottom: 25rpx; /* 设置元素间距 */
			box-shadow: 0 0 1rpx #999;
			border-radius: 10rpx;
			overflow: hidden;
			background: #FFF;
			.image{
				width: 100%;
				border-bottom: 1rpx solid $BianKuangSe;
			}
			.title{
				font-size: 32rpx;
				line-height: 40rpx;
				margin: 15rpx 20rpx;
				display: -webkit-box;
				/*!autoprefixer:off*/
				-webkit-box-orient: vertical;
				/*autoprefixer:on*/
				-webkit-line-clamp: 5;
				overflow: hidden;
			}
			.info{
				display: flex;
				justify-content:space-between;
				padding: 0 20rpx 20rpx 20rpx;
				.user{
					display: flex;
					align-items: center;
					line-height: 28rpx;
					.avatar{
						width: 40rpx;
						height: 40rpx;
						overflow: hidden;
						border-radius: 100%;
						margin-right: 10rpx;
					}
					text{
						font-size: 28rpx;
						color: $ZhanWeiSe;
					}
				}
				.comment{
					display: flex;
					align-items: center;
					line-height: 28rpx;
					text{
						font-size: 28rpx;
						color: $ZhanWeiSe;
					}
					.icon-pinglun1{
						padding-right: 5rpx;
					}
				}
			}
		}
		.page{
			display: flex;
			align-items: center;
			justify-content: center;
			line-height: 40rpx;
			font-size: 40rpx;
			color: $ZhanWeiSe;
			width: 337.5rpx;
			height: 200rpx;
		}
	}
	.loading{
		display: flex;
		flex-wrap: wrap;
		justify-content:space-between;
		.loading-css{
			width:calc(50% - 12.5rpx);
			height: 180rpx;
			margin-bottom: 25rpx; /* 设置元素间距 */
			box-shadow: 0 0 1rpx #999;
		}
	}
}
</style>